<?php

/**	
 *	lightbox module
 *	module that renders a 'lightbox' 
 *
 *	@author			pieter van peteghem <pieter@onedotonly.be>
 *
 *	@copyright		oneDot only <we@onedotonly.be>
 * 	@copyright		Copyright (c) 2010, oneDot only. All rights reserved.
 * 	@license		BSD License
 */


class MediaLightbox extends MOD {


	/**
	 *	constructor
	 *	
	 *	add module vars and reference (multiple modules on 1 page are possible)	
	 *	@param		array ($vars)
	 */
	 
	function __construct( $vars ) {
		$this->_addvars( $vars );
		$this->_ref();
	}


	/**
	 * 	define output
	 *	this is the base for rendering the stars at the frontend
	 */
	 
	public function output() {
		
		if( $this->action )
			$result = $this->{ "filter_" . $this->action }();

		$this->addclass( $this->action );
		
		if ( $result && is_array( $result ))
			$result = '<ul>' . implode( "\n", $result ) . '</ul>';
			
		return $this->parse( $result ) . $this->render_js();
		
	}
	
	
	/**
	 * 	most simple lightbox
	 *	defined by an array of images in the module vars
	 *	
	 *	@param		string	size
	 *	@param		string	thumbsize	
	 *	@param		array	picids
	 */
	public function filter_simple() {
		
		foreach( (array) $this->vars->pics as $pic ) {
			$return[] = '<li>';
			$return[] = '<a href="/public.img?id=' . $pic[ 'ID' ] . '&sze=' . $this->vars->sze . '" rel="lightbox[album' . $this->modid . ']">';
			$return[] = '<img src="/public.img?id=' . $pic[ 'ID' ] . '&sze=' . $this->vars->thumbsze . '" />';
			$return[] = '</a></li>';
		}
		
		return $return;
	
	}
	


	/**
	 * 	lightbox module define by given object
	 *	@param		string	size
	 *	@param		string	thumbsize	
	 *	@param		array	picids
	 */
	public function filter_object() {
		global $Object;
		
		if( $Object && $Object->hasMedia()) {
			
			$Album	= new OBJECT( $Object->type, (int) $Object->get( 'ID' ));
			$pics	= $Album->media->filter( "media.img" );
		
			foreach( $pics as $pic ) {
				$return[] = '<li>';
				$return[] = '<a href="http://kriski.be/public.img?id=' . $pic[ 'ID' ] . '&sze=' . $this->vars->sze . '" rel="lightbox[album' . $this->modid . ']">';
				$return[] = '<img src="/public.img?id=' . $pic[ 'ID' ] . '&sze=' . $this->vars->thumbsze . '" />';
				$return[] = '</a></li>';
			}

			return $return;
		}
	}
	
}


